package com.seehack.sample.springrest.httpclient.interceptor;

import org.apache.http.HttpRequest;
import org.apache.http.HttpRequestInterceptor;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.protocol.HttpContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class RequestConfigInterceptor implements HttpRequestInterceptor {

    private static final Logger log = LoggerFactory.getLogger(RequestConfigInterceptor.class);

    public void process(HttpRequest request, HttpContext context) {
        Object obj = context.getAttribute(HttpClientContext.REQUEST_CONFIG);
        if (request instanceof RequestConfig) {
            RequestConfig requestConfig = (RequestConfig) obj;
            log.info("RequestConfig[ connectRequestTimeout: {}ms, connectTimeout: {}ms]",
                    requestConfig.getConnectionRequestTimeout(),
                    requestConfig.getConnectTimeout());
        }
    }

}
